local sk__gushe = fk.CreateSkill {

  name = "sk__gushe",

  tags = { Skill.Compulsory, },

}



sk__gushe:addEffect(fk.PindianCardsDisplayed, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__gushe.name) then
      return player == data.from or data.results[player]
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(sk__gushe.name)
    room:notifySkillInvoked(player, sk__gushe.name, "drawcard")
    local card = event:getCostData(self)
    if player == data.from then
      card = data.fromCard
    elseif data.results[player] then
      card = data.results[player].toCard
    end
    card.number = math.min(card.number + player:getMark("@sk__wanglang_raoshe"), 13)
  end,
})
sk__gushe:addEffect(fk.PindianResultConfirmed, {
  name = "sk__gushe",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__gushe.name) then
      event:setCostData(self, nil)
      if data.winner and data.winner == player then
        if data.from == player then
          event:setCostData(self, data.toCard)
        else
          event:setCostData(self, data.fromCard)
        end
      else
        if data.from == player then
          event:setCostData(self, data.fromCard)
        elseif data.to == player then
          event:setCostData(self, data.toCard)
        end
      end
      return event:getCostData(self) and player.room:getCardArea(event:getCostData(self)) == Card.Processing
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(sk__gushe.name)
    room:notifySkillInvoked(player, sk__gushe.name, "drawcard")
    local card = event:getCostData(self)
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, sk__gushe.name, nil, true, player)
  end,
})

return sk__gushe
